<?php
namespace Admin\Controller;

/**
 * 轮播图控制器
 */
class ImagesController extends AdminController {

    public function index(){
        /* 查询条件初始化 */
        // $map = array();
        // // $map  = array('delflag' => 0);
        // // if(isset($_GET['name'])){
        // //     $map['name']    =   array('like', '%'.(string)I('name').'%');
        // // }

        // $list = $this->lists('images', $map,'createAt,id');

        $list = M('Images');
        $data = $list->where('delflag=0')->order('displayOrder')->select();
        // for($i=0;$i<8;$i+=1){
        //     var_dump(2);
        // }
        // 记录当前列表页的cookie
        Cookie('__forward__',$_SERVER['REQUEST_URI']);

        // $this->assign('list',C('CONFIG_GROUP_LIST'));
        // $this->assign('group_id',I('get.group',0));

        $this->assign('list', $data);
        $listqd = M('Images');
        $dataqd = $list->where('imageName="qd"')->select();
        $this->assign('listqd', $dataqd);
        $this->meta_title = 'images';
        $this->display();
    }

    public function uploadh(){
        $ooder = I('kk');
        //var_dump($ooder);
        if($ooder === '0'){
            $imgurl= I('h0');
            $imgtype = I('cbh0');
            $imgpath = I('imgh0');
            if($imgurl===""||$imgtype===""){
                $this->error("跳转地址或链接属性不能为空");
            }
            $imgsrc = $_FILES['lunbo0']['name'];
            if($imgpath===""&&$imgsrc===""){
                $this->error("图片不能为空");
            }
            if($imgpath!=""){
                $data['imagepath'] =  $imgpath;
            }
            if($imgsrc!=""){
                header("content-type:text/html;charset=utf-8");
                $upload = new \Think\Upload();
                $upload->maxSize = 2048*2048 ;// 设置附件上传大小 (-1) 是不限值大小
                $upload->allowExts = array('jpg', 'png', 'jpeg');// 设置附件上传类型
                $upload->savePath = 'tupian/';// 设置附件上传目录
                $upload->replace = true; //存在同名文件是否覆盖
                $upload->autoSub = true;// 是否使用子目录保存上传文件
                $info = $upload->uploadOne($_FILES['lunbo0']);
                if(!$info) {// 上传错误提示错误信息
        
                $this->error($upload->getError());
                }else{// 上传成功 获取上传文件信息
                    // var_dump($info);
                    // echo '11221';
                    // echo $info['savepath'].$info['savename'];
                    $data['imagepath'] = $info['savepath'].$info['savename'];
                }
            }
            $model = M('Images');
            $model->where("imageName='h1'")->delete();
            $data['imageURL'] = I('h0');
            $data['imageName'] = 'h1';
            $data['displayOrder'] = 1;
            $radio = I('cbh0');
            if($radio=="wangye"){
                $data['imageType'] = 1;
            }else if($radio=="danpin"){
                $data['imageType'] = 2;
            }else if ($radio=="xuanp"){
                $data['imageType'] = 3;
            }
            $data['createAt'] = NOW_TIME;
            //var_dump($data);
            $model->add($data,$options=array(),$replace=true);  
            $this->success('操作成功');
        }
        else if($ooder === '1'){
            $imgurl= I('h1');
            $imgtype = I('cbh1');
            $imgpath = I('imgh1');
            if($imgurl===""||$imgtype===""){
                $this->error("跳转地址或链接属性不能为空");
            }
            $imgsrc = $_FILES['lunbo1']['name'];
            if($imgpath===""&&$imgsrc===""){
                $this->error("图片不能为空");
            }
            if($imgpath!=""){
                $data['imagepath'] =  $imgpath;
            }
            if($imgsrc!=""){
                header("content-type:text/html;charset=utf-8");
                $upload = new \Think\Upload();
                $upload->maxSize = 2048*2048 ;// 设置附件上传大小 (-1) 是不限值大小
                $upload->allowExts = array('jpg', 'png', 'jpeg');// 设置附件上传类型
                $upload->savePath = 'tupian/';// 设置附件上传目录
                $upload->replace = true; //存在同名文件是否覆盖
                $upload->autoSub = true;// 是否使用子目录保存上传文件
                $info = $upload->uploadOne($_FILES['lunbo1']);
                if(!$info) {// 上传错误提示错误信息
        
                $this->error($upload->getError());
                }else{// 上传成功 获取上传文件信息
                    // var_dump($info);
                    // echo '11221';
                    // echo $info['savepath'].$info['savename'];
                    $data['imagepath'] = $info['savepath'].$info['savename'];
                }
            }

            $model = M('Images');
            $model->where("imageName='h2'")->delete();
            $data['imageURL'] = I('h1');
            $data['imageName'] = 'h2';
            $data['displayOrder'] = 2;
            $radio = I('cbh1');
            if($radio=="wangye"){
                $data['imageType'] = 1;
            }else if($radio=="danpin"){
                $data['imageType'] = 2;
            }else if ($radio=="xuanp"){
                $data['imageType'] = 3;
            }
            $data['createAt'] = NOW_TIME;
            //var_dump($data);
            $model->add($data,$options=array(),$replace=true);  
            $this->success('操作成功');
        }
        else if($ooder === '2'){
            $imgurl= I('h2');
            $imgtype = I('cbh2');
            $imgpath = I('imgh2');
            if($imgurl===""||$imgtype===""){
                $this->error("跳转地址或链接属性不能为空");
            }
            $imgsrc = $_FILES['lunbo2']['name'];
            if($imgpath===""&&$imgsrc===""){
                $this->error("图片不能为空");
            }
            if($imgpath!=""){
                $data['imagepath'] =  $imgpath;
            }
            if($imgsrc!=""){
                header("content-type:text/html;charset=utf-8");
                $upload = new \Think\Upload();
                $upload->maxSize = 2048*2048 ;// 设置附件上传大小 (-1) 是不限值大小
                $upload->allowExts = array('jpg', 'png', 'jpeg');// 设置附件上传类型
                $upload->savePath = 'tupian/';// 设置附件上传目录
                $upload->replace = true; //存在同名文件是否覆盖
                $upload->autoSub = true;// 是否使用子目录保存上传文件
                $info = $upload->uploadOne($_FILES['lunbo2']);
                if(!$info) {// 上传错误提示错误信息
        
                $this->error($upload->getError());
                }else{// 上传成功 获取上传文件信息
                    // var_dump($info);
                    // echo '11221';
                    // echo $info['savepath'].$info['savename'];
                    $data['imagepath'] = $info['savepath'].$info['savename'];
                }
            }
            $model = M('Images');
            $model->where("imageName='h3'")->delete();
            $data['imageURL'] = I('h2');
            $data['imageName'] = 'h3';
            $data['displayOrder'] = 3;
            $radio = I('cbh2');
            if($radio=="wangye"){
                $data['imageType'] = 1;
            }else if($radio=="danpin"){
                $data['imageType'] = 2;
            }else if ($radio=="xuanp"){
                $data['imageType'] = 3;
            }
            $data['createAt'] = NOW_TIME;
            //var_dump($data);
            $model->add($data,$options=array(),$replace=true);  
            $this->success('操作成功');
        }
        else if($ooder === '3'){
            $imgurl= I('h3');
            $imgtype = I('cbh3');
            $imgpath = I('imgh3');
            if($imgurl===""||$imgtype===""){
                $this->error("跳转地址或链接属性不能为空");
            }
            $imgsrc = $_FILES['lunbo3']['name'];
            if($imgpath===""&&$imgsrc===""){
                $this->error("图片不能为空");
            }
            if($imgpath!=""){
                $data['imagepath'] =  $imgpath;
            }
            if($imgsrc!=""){
                header("content-type:text/html;charset=utf-8");
                $upload = new \Think\Upload();
                $upload->maxSize = 2048*2048 ;// 设置附件上传大小 (-1) 是不限值大小
                $upload->allowExts = array('jpg', 'png', 'jpeg');// 设置附件上传类型
                $upload->savePath = 'tupian/';// 设置附件上传目录
                $upload->replace = true; //存在同名文件是否覆盖
                $upload->autoSub = true;// 是否使用子目录保存上传文件
                $info = $upload->uploadOne($_FILES['lunbo3']);
                if(!$info) {// 上传错误提示错误信息
        
                $this->error($upload->getError());
                }else{// 上传成功 获取上传文件信息
                    // var_dump($info);
                    // echo '11221';
                    // echo $info['savepath'].$info['savename'];
                    $data['imagepath'] = $info['savepath'].$info['savename'];
                }
            }
            
            $model = M('Images');
            $model->where("imageName='h4'")->delete();
            $data['imageURL'] = I('h3');
            $data['imageName'] = 'h4';
            $data['displayOrder'] = 4;
            $radio = I('cbh3');
            if($radio=="wangye"){
                $data['imageType'] = 1;
            }else if($radio=="danpin"){
                $data['imageType'] = 2;
            }else if ($radio=="xuanp"){
                $data['imageType'] = 3;
            }
            $data['createAt'] = NOW_TIME;
            //var_dump($data);
            $model->add($data,$options=array(),$replace=true);  
            $this->success('操作成功');
        }
        

    }
    
    public function uploadg(){
        $ooder = I('gg');
        if($ooder === '4'){
            $imgurl= I('g1');
            $imgtype = I('cbg1');
            $imgpath = I('imgg1');
            if($imgurl===""||$imgtype===""){
                $this->error("跳转地址或链接属性不能为空");
            }
            $imgsrc = $_FILES['guang1']['name'];
            if($imgpath===""&&$imgsrc===""){
                $this->error("图片不能为空");
            }
            if($imgpath!=""){
                $data['imagepath'] =  $imgpath;
            }
            if($imgsrc!=""){
                header("content-type:text/html;charset=utf-8");
                $upload = new \Think\Upload();
                $upload->maxSize = 2048*2048 ;// 设置附件上传大小 (-1) 是不限值大小
                $upload->allowExts = array('jpg', 'png', 'jpeg');// 设置附件上传类型
                $upload->savePath = 'tupian/';// 设置附件上传目录
                $upload->replace = true; //存在同名文件是否覆盖
                $upload->autoSub = true;// 是否使用子目录保存上传文件
                $info = $upload->uploadOne($_FILES['guang1']);
                if(!$info) {// 上传错误提示错误信息
        
                $this->error($upload->getError());
                }else{// 上传成功 获取上传文件信息
                    // var_dump($info);
                    // echo '11221';
                    // echo $info['savepath'].$info['savename'];
                    $data['imagepath'] = $info['savepath'].$info['savename'];
                }
            }
            $model = M('Images');
            $model->where("imageName='g1'")->delete();
            $data['imageURL'] = I('g1');
            $data['imageName'] = 'g1';
            //$data['imagepath'] =  $imgpath;
            $data['displayOrder'] = 5;
            $radio = I('cbg1');
            
            if($radio=="wangye"){
                $data['imageType'] = 1;
            }else if($radio=="danpin"){
                $data['imageType'] = 2;
            }else if ($radio=="xuanp"){
                $data['imageType'] = 3;
            }
            $data['createAt'] = NOW_TIME;
            
            $model->add($data,$options=array(),$replace=true);  
            $this->success('操作成功');

        }else if($ooder === '5'){
            $imgurl= I('g2');
            $imgtype = I('cbg2');
            $imgpath = I('imgg2');
            if($imgurl===""||$imgtype===""){
                $this->error("跳转地址或链接属性不能为空");
            }
            $imgsrc = $_FILES['guang2']['name'];
            if($imgpath===""&&$imgsrc===""){
                $this->error("图片不能为空");
            }
            if($imgpath!=""){
                $data['imagepath'] =  $imgpath;
            }
            if($imgsrc!=""){
                header("content-type:text/html;charset=utf-8");
                $upload = new \Think\Upload();
                $upload->maxSize = 2048*2048 ;// 设置附件上传大小 (-1) 是不限值大小
                $upload->allowExts = array('jpg', 'png', 'jpeg');// 设置附件上传类型
                $upload->savePath = 'tupian/';// 设置附件上传目录
                $upload->replace = true; //存在同名文件是否覆盖
                $upload->autoSub = true;// 是否使用子目录保存上传文件
                $info = $upload->uploadOne($_FILES['guang2']);
                if(!$info) {// 上传错误提示错误信息
        
                $this->error($upload->getError());
                }else{// 上传成功 获取上传文件信息
                    // var_dump($info);
                    // echo '11221';
                    // echo $info['savepath'].$info['savename'];
                    $data['imagepath'] = $info['savepath'].$info['savename'];
                }
            }
            $model = M('Images');
            $model->where("imageName='g2'")->delete();
            $data['imageURL'] = I('g2');
            $data['imageName'] = 'g2';
            //$data['imagepath'] =  $imgpath;
            $data['displayOrder'] = 6;
            //$data['imagepath'] = $info['savepath'].$info['savename'];
            $radio = I('cbg2');
            if($radio=="wangye"){
                $data['imageType'] = 1;
            }else if($radio=="danpin"){
                $data['imageType'] = 2;
            }else if ($radio=="xuanp"){
                $data['imageType'] = 3;
            }
            $data['createAt'] = NOW_TIME;
            //var_dump($data);
            $model->add($data,$options=array(),$replace=true);  
            $this->success('操作成功');
        }else if($ooder === '6'){
            $imgurl= I('g3');
            $imgtype = I('cbg3');
            $imgpath = I('imgg3');
            if($imgurl===""||$imgtype===""){
                $this->error("跳转地址或链接属性不能为空");
            }
            $imgsrc = $_FILES['guang3']['name'];
            if($imgpath===""&&$imgsrc===""){
                $this->error("图片不能为空");
            }
            if($imgpath!=""){
                $data['imagepath'] =  $imgpath;
            }
            if($imgsrc!=""){
                header("content-type:text/html;charset=utf-8");
                $upload = new \Think\Upload();
                $upload->maxSize = 2048*2048 ;// 设置附件上传大小 (-1) 是不限值大小
                $upload->allowExts = array('jpg', 'png', 'jpeg');// 设置附件上传类型
                $upload->savePath = 'tupian/';// 设置附件上传目录
                $upload->replace = true; //存在同名文件是否覆盖
                $upload->autoSub = true;// 是否使用子目录保存上传文件
                $info = $upload->uploadOne($_FILES['guang3']);
                if(!$info) {// 上传错误提示错误信息
        
                $this->error($upload->getError());
                }else{// 上传成功 获取上传文件信息
                    // var_dump($info);
                    // echo '11221';
                    // echo $info['savepath'].$info['savename'];
                    $data['imagepath'] = $info['savepath'].$info['savename'];
                }
            }
            $model = M('Images');
            $model->where("imageName='g3'")->delete();
            $data['imageURL'] = I('g3');
            $data['imageName'] = 'g3';
            //$data['imagepath'] =  $imgpath;
            $data['displayOrder'] = 7;
            $radio = I('cbg3');
            if($radio=="wangye"){
                $data['imageType'] = 1;
            }else if($radio=="danpin"){
                $data['imageType'] = 2;
            }else if ($radio=="xuanp"){
                $data['imageType'] = 3;
            }
            $data['createAt'] = NOW_TIME;
            //var_dump($data);
            $model->add($data,$options=array(),$replace=true);  
            $this->success('操作成功');
            
        }else if($ooder === '7'){
            $imgurl= I('g4');
            $imgtype = I('cbg4');
            $imgpath = I('imgg4');
            if($imgurl===""||$imgtype===""){
                $this->error("跳转地址或链接属性不能为空");
            }
            $imgsrc = $_FILES['guang4']['name'];
            if($imgpath===""&&$imgsrc===""){
                $this->error("图片不能为空");
            }
            if($imgpath!=""){
                $data['imagepath'] =  $imgpath;
            }
           
            if($imgsrc!=""){
                header("content-type:text/html;charset=utf-8");
                $upload = new \Think\Upload();
                $upload->maxSize = 2048*2048 ;// 设置附件上传大小 (-1) 是不限值大小
                $upload->allowExts = array('jpg', 'png', 'jpeg');// 设置附件上传类型
                $upload->savePath = 'tupian/';// 设置附件上传目录
                $upload->replace = true; //存在同名文件是否覆盖
                $upload->autoSub = true;// 是否使用子目录保存上传文件
                $info = $upload->uploadOne($_FILES['guang4']);
                if(!$info) {// 上传错误提示错误信息
        
                $this->error($upload->getError());
                }else{// 上传成功 获取上传文件信息
                    // var_dump($info);
                    // echo '11221';
                    // echo $info['savepath'].$info['savename'];
                    $data['imagepath'] = $info['savepath'].$info['savename'];
                }
            }
            $model = M('Images');
            $model->where("imageName='g4'")->delete();
            $data['imageURL'] = I('g4');
            $data['imageName'] = 'g4';
            $data['displayOrder'] = 8;
            $radio = I('cbg4');
            if($radio=="wangye"){
                $data['imageType'] = 1;
            }else if($radio=="danpin"){
                $data['imageType'] = 2;
            }else if ($radio=="xuanp"){
                $data['imageType'] = 3;
            }
            $data['createAt'] = NOW_TIME;
            //var_dump($data);
            $model->add($data,$options=array(),$replace=true);  
            $this->success('操作成功');
        }
    }

    public function uploadq(){
        header("content-type:text/html;charset=utf-8");
        $upload = new \Think\Upload();
        $upload->maxSize = 2048*2048 ;// 设置附件上传大小 (-1) 是不限值大小
        $upload->allowExts = array('jpg', 'png', 'jpeg');// 设置附件上传类型
        $upload->savePath = 'tupian/';// 设置附件上传目录
        $upload->replace = true; //存在同名文件是否覆盖
        $upload->autoSub = true;// 是否使用子目录保存上传文件
        $info = $upload->uploadOne($_FILES['qidong']);
        if(!$info) {// 上传错误提示错误信息

        $this->error($upload->getError());
        }else{// 上传成功 获取上传文件信息
            // var_dump($info);
            // echo '11221';
            // echo $info['savepath'].$info['savename'];
            $data['imagepath'] = $info['savepath'].$info['savename'];
        }
        $model = M('Images');
        $model->where("imageName='qd'")->delete();
        $data['imageURL'] = '';
        $data['imageName'] = 'qd';
        $data['displayOrder'] = 10;
        $data['imageType'] = 4;
        $data['createAt'] = NOW_TIME;
        //var_dump($data);
        $model->add($data,$options=array(),$replace=true);  
        $this->success('操作成功');
    }
    
}
?>